Fix HVM MSR save/restore.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 17 Feb 2006 15:29:24 +0000 (16:29 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 17 Feb 2006 15:29:24 +0000 (16:29 +0100)
Signed-off-by: Keir Fraser <keir@xensource.com>
Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Signed-off-by: Xin Li <xin.b.li@intel.com>
xen/arch/x86/domain.c
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/svm/svm.c
xen/arch/x86/hvm/vmx/vmx.c
xen/include/asm-x86/hvm/hvm.h
xen/include/asm-x86/hvm/support.h

index 1bea8813ed5611302d5a1f1f1872f6b71a08d40a..5e038cebf38e5ad4b1873472e0d1b7362d5bf854 100644 (file)
@@ -435,8 +435,6 @@ int arch_set_info_guest(
 
         if ( !hvm_initialize_guest_resources(v) )
             return -EINVAL;
-
-        hvm_switch_on = 1;
     }
 
     update_pagetables(v);
@@ -685,6 +683,8 @@ static void __context_switch(void)
                CTXT_SWITCH_STACK_BYTES);
         unlazy_fpu(p);
         save_segments(p);
+        if ( HVM_DOMAIN(p) )
+            hvm_load_msrs();
     }
 
     if ( !is_idle_vcpu(n) )
@@ -710,6 +710,10 @@ static void __context_switch(void)
             set_int80_direct_trap(n);
             switch_kernel_stack(n, cpu);
         }
+        else
+        {
+            hvm_restore_msrs(next);
+        }
     }
 
     if ( p->domain != n->domain )
@@ -765,16 +769,10 @@ void context_switch(struct vcpu *prev, struct vcpu *next)
         /* Re-enable interrupts before restoring state which may fault. */
         local_irq_enable();
 
-        if ( HVM_DOMAIN(next) )
-        {
-            hvm_restore_msrs(next);
-        }
-        else
+        if ( !HVM_DOMAIN(next) )
         {
             load_LDT(next);
             load_segments(next);
-            if ( HVM_DOMAIN(next) )
-                hvm_load_msrs(next);
         }
     }
 
index 1a0ec644c121c42ff1fb46dd83a22caf6204ac5e..bbe3af8ea63f1fce200b8d2769f0d4cb7e25cdca 100644 (file)
@@ -46,7 +46,6 @@
 #include <public/hvm/hvm_info_table.h>
 
 int hvm_enabled = 0;
-int hvm_switch_on = 0;
 
 unsigned int opt_hvm_debug_level = 0;
 integer_param("hvm_debug", opt_hvm_debug_level);
index 4aa3b89be32c68eeea2725086c78872aef67a4c5..d4af058c657aa7eb3f5031b474d29651f4eaa5e3 100644 (file)
@@ -251,14 +251,11 @@ void svm_save_segments(struct vcpu *v)
  * are not modified once set for generic domains, we don't save them,
  * but simply reset them to the values set at percpu_traps_init().
  */
-void svm_load_msrs(struct vcpu *n)
+void svm_load_msrs(void)
 {
     struct svm_msr_state *host_state = &percpu_msr[smp_processor_id()];
     int i;
 
-    if ( !hvm_switch_on )
-        return;
-
     while ( host_state->flags )
     {
         i = find_first_set_bit(host_state->flags);
index c9f3171aa73ac85595de39035c65e04856c635c7..25a76348ec42f67fe4bc0381ba92d560ff731fb2 100644 (file)
@@ -124,14 +124,11 @@ void vmx_save_segments(struct vcpu *v)
  * are not modified once set for generic domains, we don't save them,
  * but simply reset them to the values set at percpu_traps_init().
  */
-void vmx_load_msrs(struct vcpu *n)
+void vmx_load_msrs(void)
 {
     struct vmx_msr_state *host_state = &percpu_msr[smp_processor_id()];
     int i;
 
-    if ( !hvm_switch_on )
-        return;
-
     while ( host_state->flags )
     {
         i = find_first_set_bit(host_state->flags);
index 9288e465d3afe6c71aabd2aace105be62c89156e..c4386e5267d8fbbf61ff2c370579eb0140c7d3bc 100644 (file)
@@ -50,7 +50,7 @@ struct hvm_function_table {
     void (*load_cpu_guest_regs)(struct vcpu *v, struct cpu_user_regs *r);
 #ifdef __x86_64__
     void (*save_segments)(struct vcpu *v);
-    void (*load_msrs)(struct vcpu *v);
+    void (*load_msrs)(void);
     void (*restore_msrs)(struct vcpu *v);
 #endif
     void (*store_cpu_guest_ctrl_regs)(struct vcpu *v, unsigned long crs[8]);
@@ -116,10 +116,10 @@ hvm_save_segments(struct vcpu *v)
 }
 
 static inline void
-hvm_load_msrs(struct vcpu *v)
+hvm_load_msrs(void)
 {
     if (hvm_funcs.load_msrs)
-        hvm_funcs.load_msrs(v);
+        hvm_funcs.load_msrs();
 }
 
 static inline void
index 07dac5f52ee3b2b373de950a239c1ae2089ee5fc..3507e75024c50783f2f201df6d2d529ac6c7567f 100644 (file)
@@ -133,7 +133,6 @@ extern unsigned int opt_hvm_debug_level;
     } while (0)
 
 extern int hvm_enabled;
-extern int hvm_switch_on;
 
 enum { HVM_COPY_IN = 0, HVM_COPY_OUT };
 extern int hvm_copy(void *buf, unsigned long vaddr, int size, int dir);